package org.example.codeservce;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.alibaba.dashscope.app.*;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.utils.JsonUtils;
import com.wf.captcha.ArithmeticCaptcha;
import com.wf.captcha.SpecCaptcha;
import com.wf.captcha.base.Captcha;
import lombok.SneakyThrows;
import okhttp3.*;
import org.example.codeservce.util.PasswordEncryp;
import springfox.documentation.spring.web.json.Json;

import javax.servlet.http.HttpServletRequest;
import java.awt.*;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;


public class Main
{
    public static void appCall()
            throws ApiException, NoApiKeyException, InputRequiredException
    {
        RagApplicationParam param = RagApplicationParam.builder()
                .appId("b52eea9b290342818e5404017aeafa86")
                .apiKey("sk-IeCCaRJJcT")
                .prompt("如何做炒西红柿鸡蛋？")
                .build();

        Application application = new Application();
        ApplicationResult result = application.call(param);

        System.out.printf("requestId: %s, text: %s, finishReason: %s\n",
                          result.getRequestId(), result.getOutput().getText(), result.getOutput().getFinishReason());

        if (result.getUsage() != null && result.getUsage().getModels() != null)
        {
            for (ApplicationUsage.ModelUsage usage : result.getUsage().getModels())
            {
                System.out.printf("modelId: %s, inputTokens: %d, outputTokens: %d\n",
                                  usage.getModelId(), usage.getInputTokens(), usage.getOutputTokens());
            }
        }
    }


    @SneakyThrows
    public static void main(String[] args)
    {
        //算术验证码 数字加减乘除. 建议2位运算就行:captcha.setLen(2);
        SpecCaptcha  captcha = new SpecCaptcha (130, 48, 5);

// 设置内置字体
        captcha.setFont(Captcha.FONT_1);


// 设置系统字体
        captcha.setFont(new Font("楷体", Font.PLAIN, 28));
        String codeEncryption = PasswordEncryp.getPaawordEncryp(captcha.text());
        String captchaBase64 = captcha.toBase64();
        System.out.println(captchaBase64);

    }



    private static void rquestBoDY() throws IOException
    {
        HttpRequest.get("https://slxt.huluxia.cloud/sites/992.html").execute();
    }
}